<!DOCTYPE html>
<html>
	<head>
		<title>Bisectionsearch</title>
		<script type="text/javascript"></<script>
	</head>
	<body>
	 <span>测试数据：</span><span id="test1"> 1,2,3,4,5,6,7,8,9</span>
	 <br />	<button onclick="console.log()"></button>
	 <div> 数据位于第几位：</div>
	 <div id="outs1"></div>
		<script>
		function search(arr,num) {
		            var l=arr.length;
		            var left=0;
		            var right=l-1;
		            var center=Math.floor((left+right)/2);
		            while(left<=l-1&&right>=0){
		                if (arr[center]==num) return center;
		                if (left==right) return "您查找的数不存在";
		                if (arr[center]>num) {
		                    right=center-1;
		                    center=Math.floor((left+right)/2);
		                }else if (arr[center]<num) {
		                    left=center+1;
		                    center=Math.floor((left+right)/2);
		                }
		            }
		        }
		        var a=document.getElementById("test1").innerHTML;
				document.getElementById("outs1").innerHTML =console.log(search(a,6)) 
				;
        </scipt>
	</body>
</html>
